{extend name="public/base" /} {block name="css"}
<link rel="stylesheet" href="__INDEX__/css/add_clothes.css"> 
<style>
table{ width: 100%;border-collapse: collapse;}
#chanpin>tr>td{ text-align: center;border:1px solid #ccc; height: 30px;line-height: 30px;}
#chanpin tr th{ text-align: center;border:1px solid #ccc;height: 30px;line-height: 30px; }
table>tr>td{ text-align: center;border:1px solid #ccc; height: 30px;line-height: 30px;}
table tr th{ text-align: center;border:1px solid #ccc;height: 30px;line-height: 30px; }
</style>
{/block}
{block name="container"}

<div class="panel-body panel-body-nopadding" style="padding-bottom:50px;">
    <div class="inforMain">
        <div class="title">店铺成衣出库</div>
        <span>*请用扫码枪扫成衣对应的条形码*</span>
        <input type="text" id="maBoxs">
    </div>
    <div id="info" style="display: none">
        <form class="form-horizontal form-bordered" id="submitForm" action="/index/shop/chuku" method="post" style="margin:38px auto !important;" > 
            <div class="form-group" >
                <table id="chanpin">
                    <tr>
                        <th>序号</th>
                        <th>商品名称</th>
                        <th>面料编号</th>
                        <th>条码编号</th>
                        <th>面料属性</th>
                        <th>性别</th>
                        <th>季节</th>
                        <th>品类</th>
                        <th>号型</th>
                        <th>颜色</th>
                        <th>价格</th>
                        <th>剩余数量</th>
                        <th>出售数量</th>
                        <th><span style="color: #d03535">售卖价格</span></th>
                    </tr>

                </table>
                <table>
                    <tr>
                        <th width="10%">付款方式</th>
                        <th width="70%">
                            <span>
                                <input class="is_dian" type="radio" name="payment" value="1">普通支付
                            </span>
                            <span style="margin-left: 20px;">
                                <input class="is_dian" type="radio" name="payment" value="0">会员卡支付
                            </span>
                            <div style="display: inline-block;">

                                <span id="huiyuan" style="display: none;margin-left: 30px;">
                                    <span>卡号：<input type="text" name="card_num" id="card_num"></span>
                                    <span>余额：<input type="text" name="money" id="money" readonly></span>
                                    <span>密码：<input type="password" name="pass" id="pass"></span>
                                </span>
                            </div>
                        </th>
                        <th width="10%">合计</th>
                        <th width="10%"><input id="all" name="total"  value="" /></th>
                    </tr>
                </table>


            </div>
            <div class="panel-footer">
             <div class="row">
              <div class="col-sm-6 col-sm-offset-3">
                <button type="submit" class="btn btn-primary">提交</button>
                <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);">返回</button>
            </div>
        </div>
    </form>
</div>

</div>
</div>
{/block} 
{block name="js"}
<script>
    var i=0;
    var sum = 0;
    $(function(){
            // 支付方式
            $(".is_dian").click(function(){
                if($(this).val() == 1){
                    $('#huiyuan').css('display','none')
                }else{
                    $('#huiyuan').css('display','block')
                }
                
            })
            
            document.getElementById('maBoxs').focus();
            $('#maBoxs').bind('keydown', function(event) {
                if (event.keyCode == "13") {
                //回车执行查询
                var aa = $('#maBoxs').val();
                $.post('{:url("index/shop/outbound")}', {order: aa}, function(data) {
                    if(data.sus == 1){
                        i++;
                        var myDate = new Date();
                        var y = myDate.getFullYear();  //获取当前年份
                        for (var j = 0; j <= i; j++) {
                            if($('#code_'+j).val() == data['code'])
                            {
                                var num = $('#num_'+j).val();
                                num++; 
                                document.getElementById('num_'+j).value = num;
                                return false;  
                            } 
                        }
                        var html =`
                        <tr>
                        <td>`+i+`</td>
                        <td>`+data['name']+`</td>
                        <td>`+data['ml_num']+`</td>
                        <td>`+data['code']+`<input type="hidden" name="code[]" id="code_`+i+`" value ="`+data['code']+`"/></td>
                        <td>`+data['ml_style']+`</td>
                        <td>`+data['sex']+`</td>
                        <td>`+data['season']+`</td>
                        <td>`+data['category']+`</td>
                        <td>`+data['size']+`</td>
                        <td>`+data['color']+`</td>
                        <td>`+data['price']+` </td>
                        <td>`+data['num']+`<input type="hidden" id="name_`+i+`"  value="`+data['price']+`"/></td>
                        <td><input type="text" name="num[]" id="num_`+i+`" value="1"/></td>
                        <td><input type="text" style="border:none;color:red !important;width:100%;text-align:center;" value="`+data['price']+`" name="sale_price[]" onchange="jisuan()" id="jisuan_`+i+`"/></td>
                        </tr>
                        `;  
                        $('#chuku').focus();
                        $('#chanpin').append(html);

                        getAllNum(i);
                        document.getElementById('maBoxs').value = '';            
                        $('#info').css('display', 'block');
                    }else{
                       swal({
                            title: "没有此商品",      
                            text: "",
                            type: "error"
                        }); 
                   }
               });
            }
        });
        /*会员卡支付的时候先查询下能不能用  余额还剩多少*/        
        $('#card_num').bind('keydown',function(e){
            if( e.keyCode == '13'){
                $.post('{:url("index/member/getMemberInfo")}', {card_num: $('#card_num').val()}, function(data) {
                        if(data.sta ==1)/*正常用户*/
                        {
                            $('#money').val(data.money);
                        }else if(data.sta == 2)
                        {
                            swal({title: '该卡已被冻结',text: "",type: "error"});
                            document.getElementById('card_num').value = '' ; 
                        }else{
                            swal({title: '该卡号不存在',  text: "",type: "error"});
                            document.getElementById('card_num').value = '' ;
                        }
                    });    
                return false;
            }
        })
        /*会员卡验证密码的功能*/
        $('#pass').bind('keydown', function(event) {
            if(event.keyCode == '13')
            {
                
                $.post('{:url("index/member/checkPassword")}', {password: $('#pass').val(),card_num: $('#card_num').val()}, function(data) {
                    if(data.sta != 1)
                    {
                       swal({title: '密码输入错误',  text: "",type: "error"}); 
                       document.getElementById('pass').value = '' ;
                       return false;
                    }else{
                        swal({title: '密码正确',  text: "",type: "success"});
                        return false;
                    }
                });
                return false;
            }
        });
    });

    function getAllNum(id)
    {
       for(var j = 1 ; j<= id; j++)
       {
          sum = parseInt(sum) +parseInt($('#jisuan_'+j).val());
      }
      document.getElementById('all').value = sum;
      sum = 0;
    }

    function jisuan()
    {
        for (var j =  1; j <= i; j++) {
            sum = parseInt(sum) +parseInt($('#jisuan_'+j).val());
        }
        document.getElementById('all').value = sum;
        sum = 0;
    } 
</script>
{/block}